# coding: utf-8

from elasticsearch import Elasticsearch

es = Elasticsearch(hosts="172.16.202.33")
if es.indices.exists(index='wangsir'):
    es.indices.delete(index='wangsir')

INIT_MAPPING = {
    "mappings": {
        "user": {
            "properties": {
                "title": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "age": {
                    "type": "integer"
                }
            }
        },
        "blogpost": {
            "properties": {
                "title": {
                    "type": "text"
                },
                "body": {
                    "type": "text"
                },
                "user_id": {
                    "type": "keyword"
                },
                "created": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss"
                }
            }
        }
    }
}
es.indices.create(index='wangsir', body=INIT_MAPPING)

# 打印mapping
print(es.indices.get_mapping(index='wangsir'))

# 设置mapping（现在还没弄好呢，总是报错啊）
# print(es.indices.put_settings(index='wangsir', body=INIT_MAPPING))
